package com.juzipi.rabbit.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;


/**
 * @Author juzipi
 * @Date 2021/7/17 15:06
 * @Info
 */
@Configuration
public class DirectConfig {





    @Bean
    public Queue testDelayQueue(){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("x-dead-letter-exchange","DeadExchange");
        hashMap.put("x-dead-letter-routing-key","DeadRouting");
        //设置了就是所有消息过期时间都是5秒
        hashMap.put("x-message-ttl",5000);
        return new Queue("TestDelayQueue",true,false,false,hashMap);
    }

    @Bean
    public DirectExchange testDelayExchange(){
        return new DirectExchange("TestDelayExchange");
    }

    @Bean
    public Binding testDelayBinding(){
        return BindingBuilder.bind(testDelayQueue()).to(testDelayExchange()).with("TestDelayRouting");
    }

    @Bean
    public Queue deadQueue(){
        return new Queue("DeadQueue");
    }

    @Bean
    public DirectExchange testDeadExchange(){
        return new DirectExchange("DeadExchange");
    }

    @Bean
    public Binding bindingTestDeadQueue(){
        return BindingBuilder.bind(deadQueue()).to(testDeadExchange()).with("DeadRouting");
    }



    //队列
    @Bean
    public Queue mailQueue(){
        return new Queue("MailQueue",true);
    }



    //交换机
    @Bean
    public DirectExchange mailExchange(){
        return new DirectExchange("MailExchange");
    }


    //绑定
    @Bean
    public Binding bindingMailQueue(){
        return BindingBuilder.bind(mailQueue()).to(mailExchange()).with("MailRouting");
    }


    //队列
    @Bean
    public Queue mailDelayQueue(){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("x-dead-letter-exchange","MailExchange");
        hashMap.put("x-dead-letter-routing-key","MailRouting");
        return new Queue("MailDelayQueue",true,false,false,hashMap);
    }



    //交换机
    @Bean
    public DirectExchange mailDelayExchange(){
        return new DirectExchange("MailDelayExchange");
    }


    //绑定
    @Bean
    public Binding bindingMailDelayQueue(){
        return BindingBuilder.bind(mailQueue()).to(mailExchange()).with("MailDelayRouting");
    }


}
